<template>
    <div>
        <slot>
        </slot>
    </div>
</template>

<script>
import {oneOf,findComponentsDownward} from '@/utils/assist.js';
import Emitter from 'common/mixins/emitter';
export default {
    name:'iRadioGroup',
    mixins:[Emitter],
    props:{
        value:{
            type:[String,Number],
            default:''
        },
        vertical:{
            type:Boolean,
            default:false
        }
    },
    data() {
        return {
            currentValue:this.value,
            childrens:[]
        };
    },
    mounted() {
        this.updateValue();
    },
    methods:{
        updateValue() {
            this.childrens = findComponentsDownward(this,'iRadio');
            if(this.childrens) {
                this.childrens.forEach(child=>{
                    child.currentValue = this.currentValue === child.label;
                    child.group = true;
                });
            }
        },
        change(data) {
            this.currentValue = data.value;
            this.updateValue();
            this.$emit('input',data.value);
            this.$emit('on-change',data.value);
            this.dispatch('FormItem','on-form-change',data.value);
        }
    },
    watch:{
        value() {
            if(this.currentValue!==this.value) {
                this.currentValue = this.value;
                this.$nextTick(()=>{
                    this.updateValue();
                })
            }
        }
    }
}
</script>

<style>

</style>
